/*-------------------------------------------------------------------------

   File :			iso8utl.h
   Project :        VeriFone Base application
   Library :
   Description :    Header file for the ISO8583 module - Common Utilities.
   Notes :
   Modification History :
     #     Date      Who                     Description
   ----- -------- ---------- ---------------------------------------------
 **************************************************************************

   Copyright (C) 1995 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/

#ifdef ISO8583_DEFINED

#ifndef ISO8UTL
#define ISO8UTL

#include <isodefs.h>

/* ISO 8583 format specific informations */

typedef struct TagISO8583_DATA
{
	unsigned char szMerchHeader[ISO8583_MERCH_HOST_HEADER_SIZE];	/* Merchant Host Header */
	unsigned char		  btMti[ISO8583_MTI_SIZE];					/* Message Type Id		*/
	unsigned char	 btProcCode[ISO8583_PROC_CODE_SIZE];			/* Processing code		*/
	unsigned char	   btBitMap[8];									/* BitMaps				*/

	char	 szPAN[PAN_SIZE + 1];					/* Account number  */
	char szExpDate[EXP_DATE_SIZE + 1];              /* Expiration date */
	long lnSTAN;
	char szAcceptorLocation[ISO8583_CARDACC_LOC_SIZE  + 1]; 	/* Card Acceptor Location	*/

	char      szMerchType[ISO8583_MERCH_TYPE_SIZE	+ 1];	/* Merchant Type */
	char	   szAuthCode[ISO8583_AUTH_CODE_SIZE	+ 1];	/* Auth Code     */
	char	   szRespCode[ISO8583_RESP_CODE_SIZE	+ 1];	/* Response Code */
	char    szAddRespCode[ISO8583_ADDRESP_CODE_SIZE + 1];	/* Additional Response Data */
	char    szPosCondCode[ISO8583_POS_CON_SIZE		+ 1];	/* POS condition code  */
	char szSrvRestriction[ISO8583_SRV_RESTRIC_SIZE	+ 1];	/* Service Restriction Code */
	char     szTXDateTime[ISO8583_TX_DATE_TIME_SIZE + 1];	/* Transmission Date and Time */

	char	   szDate[DATE_SIZE + 1];	/* Host Txn Date        */
	char 	   szTime[TIME_SIZE + 1];	/* Host Txn Time        */
	char szSettleDate[DATE_SIZE + 1];	/* Host Settlement Date */

	char szTPDU[ISO8583_TPDU_SIZE + 1];
	char  szNII[ISO8583_NII_SIZE  + 1];	/* Network intl id      */

	unsigned char szTransactionAmtFld[ISO8583_AMT_SIZE + 1];

	char   szTerminalID[ISO8583_TID_SIZE	 + 1];
	char   szMerchantID[ISO8583_MID_SIZE	 + 1];
	char	   szBankID[ISO8583_BANK_ID_SIZE + 1];
	char szCurrencyCode[CUR_CODE_SIZE		 + 1];

	char stT1Data[TRACK1_SIZE + 1];		/* Track 1 bare format */
	char stT2Data[TRACK2_SIZE + 1];		/* Track 2 bare format */

#ifdef PAYMENT_DEFINED
	unsigned char  szInstallmentsFld[18];
#else
	char szAcceptorName[ISO8583_CARDACC_NAME_SIZE + 1]; 	/* Card Acceptor Name */
#endif /*PAYMENT_DEFINED*/
	unsigned char szAdditionalAmtFld[120 + 1];	/* Additional amounts */

	char	szPIN[PIN_SIZE + 1];	/* Pin data */
	char szPINKey[PIN_SIZE + 1];	/* Communications Key  */

	/*	Only the Private Field definitions and Host specific fields are defined in the ISO module.
		The other fields are defined in the GDS.
 	*/
	unsigned char		pszField55[		ISO8583_PVT_55_SIZE	+ 1];	/* Maximum Size of Private field 55 */
	unsigned char szExtPosCondCode[ISO8583_EXT_POS_CON_SIZE	+ 1];	/* Extended POS condition code		*/
	unsigned char szGeographicData[		ISO8583_PVT_59_SIZE	+ 1];	/* Maximum Size of Private field 59 */
	unsigned char		pszField60[		ISO8583_PVT_60_SIZE	+ 1];	/* Maximum Size of Private field 60 */
	unsigned char  	szMerchantData[ ISO8583_MERCH_DATA_SIZE	+ 1];	/* Merchant transport data			*/
	unsigned char		pszField62[		ISO8583_PVT_62_SIZE	+ 1];	/* Maximum Size of Private field 62 */
	unsigned char		pszField63[		ISO8583_PVT_63_SIZE	+ 1];	/* Maximum Size of Private field 63 */
	unsigned char		pszField64[16 + 1];							/* Mac */

#ifdef ISO8583_EXTENDED_BITMAP

	char	   szSettleCode[ISO8583_SETTLE_CODE_SIZE		+ 1];
	char   szNetMgnInfoCode[ISO8583_NETMGN_INFOCODE_SIZE	+ 1];

	unsigned char pszField74[350		  + 1];
	unsigned char pszField75[FIELD75_SIZE + 1];
	unsigned char pszField76[FIELD76_SIZE + 1];
	unsigned char pszField77[FIELD77_SIZE + 1];
	unsigned char pszField80[FIELD80_SIZE + 1];
	unsigned char pszField81[FIELD81_SIZE + 1];
	unsigned char pszField86[FIELD86_SIZE + 1];
	unsigned char pszField87[FIELD87_SIZE + 1];
	unsigned char pszField88[FIELD88_SIZE + 1];
	unsigned char pszField89[FIELD89_SIZE + 1];

	char szOrigDataElements[ISO8583_ORIGDATA_ELEMENTS_SIZE	+ 1];
	char  szMsgSecurityCode[ISO8583_MSG_SECURITYCODE_SIZE	+ 1];

	unsigned char pszField97[FIELD97_SIZE + 1];

	char szSettleInstIDCode[ISO8583_SETTLE_INSTIDCODE_SIZE	+ 1];
	char szReceivInstIDCode[ISO8583_RECEIV_INSTIDCODE_SIZE	+ 1];
	char   szTrtDescription[ISO8583_TRT_DESCRIPTION_SIZE	+ 1];
														 /* Deluxe Host definition */
	unsigned char pszField111[ISO8583_PVT_111_SIZE + 1]; /* Maximum Size of Private field 111 */
	unsigned char pszField113[ISO8583_PVT_113_SIZE + 1]; /* Maximum Size of Private field 113 */
	unsigned char pszField120[ISO8583_PVT_120_SIZE + 1]; /* Maximum Size of Private field 120 */
	unsigned char pszField122[ISO8583_PVT_122_SIZE + 1]; /* Maximum Size of Private field 122 */
	unsigned char pszField123[ISO8583_PVT_123_SIZE + 1]; /* Maximum Size of Private field 123 */
	unsigned char pszField124[ISO8583_PVT_124_SIZE + 1]; /* Maximum Size of Private field 124 */
	unsigned char pszField125[ISO8583_PVT_125_SIZE + 1]; /* Maximum Size of Private field 125 */
	unsigned char pszField126[ISO8583_PVT_126_SIZE + 1]; /* Maximum Size of Private field 126 */
	unsigned char pszField127[ISO8583_PVT_127_SIZE + 1]; /* Maximum Size of Private field 127 */
	unsigned char pszField128[16 + 1];					 /* Mac */

#endif  /* ISO8583_EXTENDED_BITMAP */

} ISO8583_DATA;

#define ISO8583_DATA_SIZE      sizeof(ISO8583_DATA)

typedef struct TagISO8583_BATCH_DATA
{
	char szPOSEntryMode[ISO8583_POS_EM_SIZE + 1];   /* POS Entry mode   */
	char szRetRefNum[ISO8583_RET_REF_SIZE + 1];     /* Retrvl ref num   */
	unsigned char btMti[ISO8583_MTI_SIZE];             		/* Message Type Id  */
	unsigned char btProcCode[ISO8583_PROC_CODE_SIZE];    /* Trans proc code  */
} ISO8583_BATCH_DATA;

#define SIZE_ISO8583_BATCH_DATA     sizeof(ISO8583_BATCH_DATA)

/* batch field ids */
#define FID_ISO_HOST_DATA_ID		0x00A1
#define FID_ISO_REVERSAL_FLAG_DATA_ID	0x00A2

/* prototypes */
void vdSetISOHostData(BATCH_REC *psrBRec, char *pchData);
void vdGetISOHostData(BATCH_REC *psrBRec, char *pchData);
void vdSetISOReversalFlag(BATCH_REC *psrBRec, VS_BOOL fData);
VS_BOOL fGetISOReversalFlag(BATCH_REC *psrBRec);

extern unsigned char stOptionalMapISO8583[];
extern unsigned char stMapISO8583[];
extern ISO8583_DATA  srISO8583;                              /* ISO specific data */
extern ISO8583_BATCH_DATA srISO8583Batch;

long lnGetISOEMessage(int inStatus);
long lnGetISOMessage(int inCode);
void vdRunLoadFieldFunc (int, PACKET_OBJECT *);
void vdOverLoadISO8583LoadFieldFunc (void (*vdNewISO8583LoadFieldFunc)(), int inFieldNum);
void vdOverLoadGetISO8583pad_nibble( unsigned char (*ucNewGetISO8583pad_nibble)(int));
void vdSkipISO8583LoadField (int inFieldNum);


int inISO8583LoadTransData (char *, void *);

int inComputeField   (int, unsigned char *, int *, int *, unsigned char *, int);
int inComputeField64 (int, unsigned char *, int *, int *);
#ifdef ISO8583_EXTENDED_BITMAP
int inComputeField128(int, unsigned char *, int *, int *);
#endif /* ISO8583_EXTENDED_BITMAP */

int inProcessField04(PACKET_OBJECT *, char *);
int inProcessField52(PACKET_OBJECT *);
void vdSkipISOLoadField (int);
int inDefaultProcessField62 (int);
void vdOverLoadProcessField62 (int (*inNewProcessField62)());
int inDefaultGetTransactionCode(TRANSACTION_OBJECT *);
void vdOverLoadGetTransactionCode( int (*inNewGetTransactionCode)());

extern int (*inGetTransactionCode)(TRANSACTION_OBJECT *);
extern int (*inProcessField62)(int);

void vdISO8583LoadField02 (PACKET_OBJECT *);
void vdISO8583LoadField03 (PACKET_OBJECT *);
void vdISO8583LoadField04 (PACKET_OBJECT *);
void vdISO8583LoadField07 (PACKET_OBJECT *);
void vdISO8583LoadField11 (PACKET_OBJECT *);
void vdISO8583LoadField12 (PACKET_OBJECT *);
void vdISO8583LoadField13 (PACKET_OBJECT *);
void vdISO8583LoadField14 (PACKET_OBJECT *);
void vdISO8583LoadField15 (PACKET_OBJECT *);
void vdISO8583LoadField18 (PACKET_OBJECT *);
void vdISO8583LoadField22 (PACKET_OBJECT *);
void vdISO8583LoadField24 (PACKET_OBJECT *);
void vdISO8583LoadField25 (PACKET_OBJECT *);
void vdISO8583LoadField32 (PACKET_OBJECT *);
void vdISO8583LoadField35 (PACKET_OBJECT *);
void vdISO8583LoadField37 (PACKET_OBJECT *);
void vdISO8583LoadField38 (PACKET_OBJECT *);
void vdISO8583LoadField39 (PACKET_OBJECT *);
void vdISO8583LoadField41 (PACKET_OBJECT *);
void vdISO8583LoadField42 (PACKET_OBJECT *);
void vdISO8583LoadField43 (PACKET_OBJECT *);
void vdISO8583LoadField45 (PACKET_OBJECT *);
void vdISO8583LoadField48 (PACKET_OBJECT *);
void vdISO8583LoadField49 (PACKET_OBJECT *);
void vdISO8583LoadField52 (PACKET_OBJECT *);
void vdISO8583LoadField54 (PACKET_OBJECT *);
void vdISO8583LoadField55 (PACKET_OBJECT *);
void vdISO8583LoadField58 (PACKET_OBJECT *);
void vdISO8583LoadField59 (PACKET_OBJECT *);
void vdISO8583LoadField60 (PACKET_OBJECT *);
void vdISO8583LoadField61 (PACKET_OBJECT *);
void vdISO8583LoadField62 (PACKET_OBJECT *);
void vdISO8583LoadField63 (PACKET_OBJECT *);
void vdLoadDummy (PACKET_OBJECT *);

#ifdef PROCESS8583_DEFINED
#include <iso8583.h>
extern int process_ISO8583 (int, field_struct *, unsigned char *, unsigned char *, int);
extern void ISO8583_main(converters * pConvertTable, fn Ret1, fn Ret2, unsigned char *szdst_8583 ,unsigned char *szsrc_8583);
extern void set_dst_ISO8583(unsigned char *dest);
extern void set_src_ISO8583(unsigned char *src);
extern void get_dst_ISO8583(unsigned char **dest);
extern void get_src_ISO8583(unsigned char **src);
extern int get_fn_ISO8583(void);


extern void ISO8583asc_to_asc(int);
extern void ISO8583asc_to_bcd(int);
extern void ISO8583asc_to_str(int);
extern void ISO8583bcd_to_asc(int);
extern void ISO8583bcd_to_bcd(int);
extern void ISO8583bcd_to_snz(int);
extern void ISO8583bcd_to_str(int);
extern void ISO8583av2_to_str(int);
extern void ISO8583av3_to_av3(int);
extern void ISO8583av3_to_str(int);
extern void ISO8583str_to_asc(int);
extern void ISO8583str_to_av2(int);
extern void ISO8583str_to_av3(int);
extern void ISO8583str_to_bcd(int);
extern void ISO8583str_to_bv2(int);
extern void ISO8583str_to_xbc(int);
extern void ISO8583bv2_to_str(int);
extern void ISO8583xbc_to_str(int);
extern void ISO8583bin_to_hst(int);
extern void ISO8583bi2_to_hst(int);
extern void ISO8583bi3_to_hst(int);
extern void ISO8583bit_to_bit(int);
extern void ISO8583hst_to_bin(int);
extern void ISO8583hst_to_bi2(int);
extern void ISO8583hst_to_bi3(int);

extern void ISO8583bv3_to_str(int);
extern void ISO8583str_to_bv3(int);

#endif /* PROCESS8583_DEFINED */
#endif /* ISO8UTL */
#endif /* ISO8583_DEFINED */

